<?php
class usrjobshistory_model extends CI_Model {
  function __construct(){
      parent::__construct();
      $this->tableName = "usr_jobs_history";
  }
  function insert($id_alumni, $company_id, $position, $year_in, $year_out){
      $dt = array("mpa_id_alumni" => $id_alumni, 
      "company_id" => $company_id, 
      "ujh_position" => $position, 
      "ujh_year_in" => $year_in, 
      "ujh_year_out" => $year_out);
      $this->db->insert($this->tableName, $dt);
      return $this->db->insert_id();
  }
  
  function update($id, $dt, $where=""){
      $this->db->where("ujh_id", $id);
      if($where != "")$this->db->where($where);
      $this->db->update($this->tableName, $dt);
  }
  
  function delete($id,  $where = ""){
      $this->db->where("ujh_id", $id);
      if($where != "")$this->db->where($where);
      $this->db->delete($this->tableName);
  }
  
  function getById($id,  $where=""){
      $this->db->where("ujh_id", $id);
      if($where != "")$this->db->where($where);
      return $this->db->get($this->tableName)->row();
  }
  
  function getByUser($id_alumni){
      $this->db->join('company', 'company.company_id = usr_jobs_history.company_id');
      $this->db->where("mpa_id_alumni", $id_alumni);
      $this->db->order_by("ujh_year_in", "asc");
      return $this->db->get($this->tableName)->result();
  }
  
  function getAll($startpage="0", $perpage="10", $where = "", $orderby=""){
      if($where != "")$this->db->where($where);
      $this->db->limit($perpage, $startpage);
      if($orderby != "")$this->db->order_by($orderby);
      return $this->db->get($this->tableName)->result();
  }
  
  function getAllCount($where = ""){
      $this->db->select("COUNT(*) JUMLAH");
      $this->db->from($this->tableName);
      if($where != "")$this->db->where($where);
      return $this->db->get()->row()->JUMLAH;
  }
}
?>